package com.gfwy.proxy;

import java.util.List;

import com.gfwy.dao.IEssayDao;
import com.gfwy.dao.impl.EssayDaoImpl;
import com.gfwy.dbc.DatabaseConnection;
import com.gfwy.vo.Essay;

public class EssayDaoProxy implements IEssayDao {
	IEssayDao dao = null;
	DatabaseConnection dbc = null;
	public EssayDaoProxy() {
		try {
			this.dbc = new DatabaseConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.dao = new EssayDaoImpl(this.dbc.getConnection());
	}	
	@Override
	public boolean doCreate(Essay e) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doCreate(e);
		} catch (Exception e2) {
			throw e2;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public boolean doUpdate(Essay e) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doUpdate(e);
		} catch (Exception e2) {
			throw e2;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public boolean doDelete(int eid) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doDelete(eid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}

	@Override
	public int count(String keyWord) throws Exception {
		int count = 0;
		try {
			count = this.dao.count(keyWord);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return count;
	}

	@Override
	public List<Essay> findAll(String keyWord, int startIndex, int count)
			throws Exception {
		List<Essay> list = null;
		try {
			list = this.dao.findAll(keyWord, startIndex, count);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}

	@Override
	public Essay findById(int eid) throws Exception {
		Essay essay = null;
		try {
			essay = this.dao.findById(eid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return essay;
	}
	@Override
	public List<Essay> findOrderByClick() throws Exception {
		List<Essay> list = null;
		try {
			list = this.dao.findOrderByClick();
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}
	@Override
	public List<Essay> findReferences(int eid, int cid, int size)
			throws Exception {
		List<Essay> list = null;
		try {
			list = this.dao.findReferences(eid, cid, size);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}
	@Override
	public List<Essay> findByCid(int cid) throws Exception {
		List<Essay> list = null;
		try {
			list = this.dao.findByCid(cid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}

}
